<style>
.layui-input-block{
margin-left:120px;
}
</style>
<!-- start form -->
<form class="layui-form" action="" id="orderEditForm">
	<div class="layui-row" style="margin-top:10px;">
	      <div class="layui-col-xs6 layui-col-sm6 layui-col-md6">
	          <label class="layui-form-label" style="width:120px;">公司名称：</label>
	          <div class="layui-input-block" style="width:200px;">
	              <select  name="companyId" id="companyId" lay-verify="required" lay-filter="onchange">
	              	  <option value="-1">请选择公司</option>
	                  <option th:each="ec:${actCenterCompanyMap}" th:value="${ec.id}" th:text="${ec.name}"></option>
	              </select>
	          </div>
	      </div>
	
	      <div class="layui-col-xs6 layui-col-sm6 layui-col-md6">
	          <label class="layui-form-label" style="width:120px;">类型：</label>
	          <div class="layui-input-block" style="width:200px;">
				 <input type="text" readonly class="layui-input" th:value="${type.value}">
				  <input type="hidden" class="layui-input" name="type" th:value="${type.code}">
	          </div>
	      </div>
	       </div>
	       
	        <div class="layui-row"  style="margin-top:10px;">
	     
	    
	          <div class="layui-col-xs6 layui-col-sm6 layui-col-md6">
	          <label class="layui-form-label" style="width:120px;">姓名：</label>
	          <div class="layui-input-block" style="width:200px;">
	              <input type="text" class="layui-input" name="name" required >
	          </div>
	      </div>
	      <div class="layui-col-xs6 layui-col-sm6 layui-col-md6">
	          <label class="layui-form-label" style="width:120px;">联系电话：</label>
	          <div class="layui-input-block" style="width:200px;">
	              <input type="text" class="layui-input" name="phone" lay-verify="required|phone">
	          </div>
	      </div>
	       </div>
	       
   <div class="layui-row"  style="margin-top:10px;">
   
	        <div class="layui-col-xs6 layui-col-sm6 layui-col-md6">
	          <label class="layui-form-label" style="width:120px;">部门名称：</label>
	          <div class="layui-input-block" style="width:200px;">
	             <select name="departmentId" id="departmentId"  lay-filter="onchange" lay-verify="required"></select>
	          </div>
	      </div>
	      
	        <div class="layui-col-xs6 layui-col-sm6 layui-col-md6">
	          <label class="layui-form-label" style="width:120px;">分管员工：</label>
	          <div class="layui-input-block" style="width:200px;">
	              <select name="staffId" id="staffId"  lay-filter="staffId" lay-verify="required"></select>
	          </div>
	      </div>
	      
	      
	       </div>
  
   <div class="layui-row"  style="margin-top:10px;">
   
	      		 <div class="layui-col-xs6 layui-col-sm6 layui-col-md6">
	          <label class="layui-form-label" style="width:120px;">分类：</label>
	          <div class="layui-input-block" style="width:200px;">
	              <select  id="catagory" name="catagory" lay-verify="required">
	                  <option value="-1" selected>请选择分类</option>
	                  <option th:each="ec:${catagoryList}" th:value="${ec.code}" th:text="${ec.value}"></option>
	              </select>
	          </div>
	      </div>   
   
	      <div class="layui-col-xs6 layui-col-sm6 layui-col-md6">
	          <label class="layui-form-label" style="width:120px;">编码：</label>
	          <div class="layui-input-block" style="width:200px;">
	              <input type="text" class="layui-input" name="no" required >
	          </div>
	      </div>
	    
	       </div>
   <div class="layui-row"  style="margin-top:10px;">
	      <div class="layui-col-xs6 layui-col-sm6 layui-col-md6">
	          <label class="layui-form-label" style="width:120px;">地址：</label>
	          <div class="layui-input-block" style="width:200px;">
	              <input type="text" class="layui-input" name="address">
	          </div>
	      </div>
	      <div class="layui-col-xs6 layui-col-sm6 layui-col-md6">
	          <label class="layui-form-label" style="width:120px;">法人：</label>
	          <div class="layui-input-block" style="width:200px;">
	              <input type="text" class="layui-input" name="corporate" lay-verify="required">
	          </div>
	      </div>
	       </div>
   <div class="layui-row"  style="margin-top:10px;">
	      <div class="layui-col-xs6 layui-col-sm6 layui-col-md6">
	          <label class="layui-form-label" style="width:120px;">银行：</label>
	          <div class="layui-input-block" style="width:200px;">
	              <input type="text" class="layui-input" name="bank" lay-verify="required">
	          </div>
	      </div>
	      <div class="layui-col-xs6 layui-col-sm6 layui-col-md6">
	          <label class="layui-form-label" style="width:120px;">银行账号：</label>
	          <div class="layui-input-block" style="width:200px;">
	              <input type="text" class="layui-input" name="bankAccount" lay-verify="required|number">
	          </div>
	      </div>
	       </div>
   <div class="layui-row"  style="margin-top:10px;">
	      <div class="layui-col-xs6 layui-col-sm6 layui-col-md6">
	          <label class="layui-form-label" style="width:120px;">税率：</label>
	          <div class="layui-input-inline" style="width:200px;">
	              <input type="text" class="layui-input" name="taxRate" lay-verify="required">
	          </div>
	      </div>
	      <div class="layui-col-xs6 layui-col-sm6 layui-col-md">
	          <label class="layui-form-label" style="width:120px;">图片地址：</label>
	          <div class="layui-input-block" style="width:200px;">
	              <input type="text" class="layui-input" name="businessLicense">
	          </div>
	      </div>
	       </div>
   <div class="layui-row"  style="margin-top:10px;">
	      <div class="layui-col-xs6 layui-col-sm6 layui-col-md6">
	          <label class="layui-form-label" style="width:120px;">说明：</label>
	          <div class="layui-input-block" style="width:200px;">
	              <textarea class="layui-textarea"   style="min-height: 50px;" name="remark"></textarea>
	          </div>
	      </div>
   </div>
   <div class="layui-row"   style="margin-top:20px;">
	    <div class="layui-col-xs12 layui-col-sm12 layui-col-md12" style="text-align:center;">
	          <button class="layui-btn" lay-submit="" lay-filter="formSubmit" authcode="900319">提交</button>
	      	<button type="button" class="layui-btn layui-btn-primary" id="closeBtn">关闭</button>
	    </div>
  </div>
</form>
<!-- end form -->
<script>
layui.use('form',function() {
	var form = layui.form;
	form.render();
	//表单提交监听
	form.on('submit(formSubmit)',function(data) {
		 $.ajax({url:'/com/supplier/customer/provider/add',
				data:$("#orderEditForm").serializeJson(),
				type:"get",
				contentType:"application/json",
				success:function(data){
					if(data.code==200){
						layer.msg("数据保存成功！");
						reloadData();
						layer.closeAll();
					}else{
						layer.msg(data.message);
					}
				}});
			return false;
	});
	//监听select onchange
	var companyId
	form.on('select(onchange)',function(data) {
		console.log(data.elem.name);
// 		console.log("companyId="+data.value);
		if(data.elem.name == "companyId") {
			companyId = data.value;//被选中的值
			console.log("companyId="+companyId);
			if(companyId == -1) {
				layer.msg("请选择公司");
				return false;
			}
			//获取部门信息
			$.getJSON("/com/supplier/customer/getDeptById?companyId="+data.value,function(dataList) {
					 var html = [];
					  html.push("<option value=''>请选择分管部门</option>")
					  $.each(dataList,function(i,item){
						  html.push("<option value='"+item.id+"'>"+item.name+"</option>")
					  });
					  $("select[name='departmentId']").html(html.join(""));
		              form.render('select');
				
			});
		}else if(data.elem.name == "departmentId") {
			console.log("companyId2="+companyId);
			var deptId = data.value;
			$.getJSON("/com/supplier/customer/getStaffById?deptId="+deptId+"&companyId="+companyId,function(staffs) {
				 var html = [];
				  html.push("<option value=''>请选择分管人员</option>")
				  $.each(staffs,function(i,item) {
					  html.push("<option value='"+item.id+"'>"+item.name+"</option>");
				  });
				  $("select[name='staffId']").html(html.join(""));
	              form.render('select');
			});
		}
	});
	//监听部门的选择
	form.on();
	//关闭
	$("#closeBtn").click(function() {
		layer.closeAll();
	});
	function reloadData(){
		$(".layui-laypage-btn")[0].click();//页面的确定按钮
	}
});
</script>